Web services provide a standard means of interoperating between software applications running on a variety of platforms and frameworks. These services form the basis of a connection technology such that services are connected together into a Service Oriented Architecture (SOA). Further, services communicate with each other using web services, the most–used connection technology of SOA. Web services effectuate a standardized way of integrating web-based applications using XML, Simple Object Access Protocol (SOAP), Web Services Description Language (WSDL), and UDDI open standards over an internet protocol.
A web service is offered by an electronic device to another electronic device, communicating with each other via the World Wide Web. It is also true that a failed web service wreaks havoc not only for the managers but also for the administrators who are responsible for the server’s well–being. A failure also causes problems for the clients trying to call a particular web service.
The most important primary elements of web services are repositories, messaging, and service. Since web services are distributed over networks and applications, the testing requirements need to be inclusive of the interfaces.
Web services are inherently vulnerable to additional risks in the areas of integration and interoperability. They can be implemented using any programming language on any platform, provided that a standardized XML interface description called WSDL is available. A standardized messaging protocol called SOAP is also used at the same time. Web services often run over HTTP but may run over other application layer transport protocols as well. Automating web services testing facilitates the reduction of overall testing efforts.
What are the challenges faced by web services?
- Lack of assurance of trustworthiness
- Improper provision of client’s input parameters
- Malicious users can manipulate the different parameters at times to draw unauthorized information
- Unavailability of source code hinders white-box testing
Web Services Testing
Web services provide seamless connections from one software application to another over private intranets and the Internet. Web services testing considers functionality and load aspects to check how a web service performs for single clients and scales as the number of clients accessing it increases.
Testing of web services is useful to prevent late detection of errors, which requires complex and costly repairs. It enables the detection of errors, evaluation, and approval of system qualities at an earlier stage. An automated test approach, in particular, helps to efficiently repeat tests whenever needed. In particular, test automation will be essential to a sound and efficient web services development process, for the assessment of the functionality, performance, and scalability of web services.
Web services testing includes:
- Generate the client or skeleton code for the web service
- Define the required test inputs
- Invoke the web service using the client or skeleton code
- Client or skeleton code generation and response verification
- Verify that the actual response is similar to that of the expected outcome
Web services testing tools
There are various web services testing tools available, such as SoapUI, TestMaker, WebInject, etc. These tools are built on open–source tools/libraries/frameworks and thus help reduce overall costs and help increase automation efficiency by minimizing initial coding effort. These tools help to quickly create and execute automated functional, regression, compliance, and loading tests. Finally, they help reduce dependency on technically skilled resources.
Web services test automation framework features
- Customizable frameworks developed based on the need
- Flexible test suites and test cases can be configured
- Enables test script creation with minimal coding effort
- Instantly sets the headers and assertions for SOAP requests
- Easily parses the XML requests with inputs
- Minimal or no scripting required from the end–user\
- Enhanced reports and logs provided for reference and future action
Benefits of adopting web services test automation frameworks
- Improves performance and reliability of the SOA
- Eases testing of both SOA-based and REST API-based web services
- Supports test execution of web services in a cloud environment
- Ensures 100% Functional Test coverage
Web Services Automation Testing Tools
Various web services automation testing tools are given below:
SoapUI
SoapUI is an open-source tool used by developers and testers to increase the delivery rate of their REST and SOAP APIs. The pro version of SoapUI is known as ReadyAPI. It helps in integrating automated API into the delivery pipeline with the aid of next-generation tools. Its Resource Centre help beginners to get started with API testing.
SoapUI Features:
- SoapUI helps in performing API functional testing to make sure that the web service is functioning as intended.
- This tool tests the performance of a web service by executing a load test on it with the help of virtual users.
- It can also help in ensuring the security of the third-party APIs, public APIs, or vulnerable internal APIs.
- The user if this tool can save his time and money by virtualizing the resources a properly built API may use from the business.
- Test coverage and speed can be increased with the aid of data-driven testing.
- A detailed testing report is provided by it to improve the testing and analyse the results.
The simplest and easiest way to integrate Selenium with Soapui is to use Groovy. SoapUI extensively supports Groovy. Groovy is an object-oriented scripting language. Groovy includes all the Java libraries. So all Java related keywords and functions can be used in the groovy script directly. It integrates with JVM (Java Virtual Machine).
@when("<I use the weather service to get the weather information")
public void i_use_the_weather_service_to_get_the_information() {
Set<Entry<String, string>> set = zipAndCities.entrySet();
while (iterator,hasNext)) {
Entry<String, String> entry = iterator.next();
String zipCode = entry.getkey();
String city = entry.getValue();
String[] prop = {"usePropertyFileFlag=true","zipCode=" +zipCode, "city=" +city};
try{
SoapUITestCaseRunner soapUITestCaseRunner = new SoapUITestCaseRunner();
soapUITestCaseRunner.setProjectFile("src/test/resources/WeatherSoapTest-soapui-project.xml");
soapUITestCaseRunner.setProjectProperties(prop);
soapUITestCaseRunner.setTestSuite("TestSuite1");
soapUITestCaseRunner.setTestCase("TestCase1");
soapUITestCaseRunner.run();
} catch (Exception e) {
System.err.println("checking" + zipCode + " failed!");
failureCount++;
zipCodes.append(zipCode + " [" + city +"] ");
e.printStackTrace();
}finally{
totalCount++;
}
}
}
}
Postman
Postman is another tool for automating web services testing by integrating it into the CI/CD pipeline. With the help of automated tests, it is possible to perform the same created test suites again and again without any chance of human error. With Postman you can perform unit tests, functional tests, integration tests, end to end tests, regression tests, mock tests on your API.
Postman features
By integrating created test suites into the CI\CD pipeline it is possible to execute it on every new push to the API. Postman allows integration of Jenkins for creating your CI\CD pipeline. It helps in ensuring the sanity of the development code. Automated testing with the command line tools, Postman and Newman, users can reduce the risks of breakage by increasing the coverage and rate of testing to develop a robust and bug resistant program.
Web services automation testing leads to less expense on QA, less lag between development and QA, along with that it also reduces the bug removal time.
Postman Example:
If you’re asked to test an API, the first thing you should be asking for is a document that describes what the API is all about. Without that, there’s no way to know what the API does, how to test it and how it should be implemented in the system. There’s no guessing here.
- Open Postman and after then My Workspace
- Copy the API and paste it into the Enter request URL
- Select API method (GET, POST, PUT, PATCH, etc.)
- Send the request
If the return status code is between 200-224, the request is successful. A token is generated that is required to authenticate other APIs.
JMeter
JMeter is an Apache product that can be used as web services automation testing tool. It is a Java application and can execute the load test, check the functionality of the system and measure its performance. The performance of both the static and dynamic resources can be tested with JMeter. It is possible to simulate a heavy load on a server, group of servers, network or object. It helps in evaluating its ability to perform under various locations ad conditions that might exist in the real operating scenario.
Jmeter Features
-
- Different applications, servers, protocols it can test are:
- Web – HTTP, HTTPS
- SOAP or REST web services
- Databases via JDBC
- And many more
- The JMeter IDE is fully featured to allow fast recording, building and debugging of test plans.
- It is possible to perform a load test from any Java-compatible OS like Linux, Windows, etc using Command-line mode.
- It provides a dynamic HTML test report that is ready to present.
- Test results can be cached and analysed while being offline.
- Different applications, servers, protocols it can test are:
Jmeter Example
Here is an example of how you could automate API testing using JMeter:
- Start by adding a Thread Group to your Test Plan and configuring the desired number of threads (users) and loop iterations.
- Next, add an HTTP Request element to the Thread Group. In the “Server Name or IP” field, enter the base URL for the API. For example, if the API is located at “https://api.example.com/v1”, you would enter “api.example.com” in this field.
- In the “Path” field, specify the path for the API endpoint you want to call. For example, if you want to call the “GET /users” endpoint, you would enter “/users” in this field.
- Select the appropriate HTTP method (e.g. GET, POST, PUT, DELETE) in the “Method” dropdown.
- If the API requires any parameters or a request body, you can specify them in the “Parameters” or “Body Data” tabs.
- Optionally, you can add a “Response Assertion” element to your Thread Group to verify that the API response meets certain criteria. For example, you might want to assert that the response status code is 200, or that the response body contains a certain string.
- To view the results of the test, you can add a “View Results Tree” listener to your Thread Group. This will show you the details of each request and response, as well as any assertions that have been applied.
Here is some sample code that demonstrates these steps:
ThreadGroup
HTTP Request
Server Name or IP: api.example.com
Path: /users
Method: GET
Response assertion
Response Code: 200
Contains: Success
Views results tree
Katalon
Katalon is another tool used to automate Web, API, mobile and desktop tests that can be deployed on operating systems like Windows, macOS, Linux.
Katalon Features
- Codeless service is available to help beginners with less or no testing experience.
- This platform is used by more than 65k companies from over 160 countries. It has hundreds of repositories and offers online courses to help testers.
- The Katalon’s IDE is productive enough to help the easy creation of automated tests. Tests can be generated for any OS or platform, no matter how complex the application is.
- Testers can also use built-in project templates, test case libraries, keywords and object repositories for a quick start.
- It can be used to perform all kinds of end to end testing.
- It is easy to locate, detect and store object which makes the scripting process fast.
- All the UI elements can be automatically stored to maximize reusability.
Katalon Example
This code defines a createUser function that sends a POST request to the specified API endpoint with the specified payload in the request body. It also defines a verifyCreateUser function that verifies the response from the createUser function.
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webservice.verification.WSResponseManager
def baseUrl = "https://api.example.com"
def headers = [
"Content-Type": "application/json"
]
def apiPath = "/users"
def payload = {
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com"
}
@Keyword
def createUser() {
def response = WS.sendRequest(
method: "POST",
url: baseUrl + apiPath,
headers: headers,
body: payload,
failOnFailingStatus: true,
saveResponseTo: "createUserResponse"
)
return response
}
@Keyword
def verifyCreateUser() {
WSResponseManager.verifyResponse(
response: createUser(),
responseObject: ResponseObject.ResponseObject(),
failureHandling: FailureHandling.CONTINUE_ON_FAILURE
)
}
To use these functions, you would call them in your test case as follows:
createUser()
verifyCreateUser()
This would send the POST request to the API and verify the response.
Conclusion
Web services enable two machines or applications to communicate with each other and exchange information. The functionality, usability, performance, and other non-functional aspects of an application depend on the effectiveness of this communication. This is what web services testing ascertain. Automating web services testing is the need of the current development world. Since automation does not require continuous human presence, so it makes test more time and efforts efficient. It allows performing that test which is not possible to execute earlier because of human limitations to perform repeated tasks again.